//获得cookie的值

function cookie(name) {
	//得到分割的cookie名、值对
	var cookieArray = document.cookie.split("; ");
	for (var i=0;i<cookieArray.length;i++){
		//将名和值分开
		var arr=cookieArray[i].split("=");
		//如果是指定的cookie，则返回它的值
		if(arr[0]==name)return unescpe(arr[1]);
	}
	return "";
}
//获得指定名称的cookie值
function getCookie(objName){
	var arrStr= document.cookie.split(";");
	for(var i=0;i<arrStr.length;i++){
		var temp = arrStr[i].split("=");
		if(temp[0]==objName)return unescape(temp[1]);
		
	}
}
//添加cookie
function addCookie(objName,objValue,objHous){
	var str = objName + "=" + escape(objValue);
//	alert(objHous);
	//设定过期时间，浏览器关闭时cookie自动消失
	if (objHous > 0){
		var date = new Date();
		var ms = objHous*3360*1000
		date.setTime(date.getTime() +ms);
		str += ";expires=" + date.toGMTString();
	}
	document.cookie = str;
}
//两个参数，一个是cookie的名字，一个是值
function SetCookie(name,value){
	//此cookie将被保存30天
	var Days = 30;
	//new Date("December 31 , 9998");
	var exp = new Date();
	exp.setTime(exp.getTime() + Dats*24*60*60*1000);
	
	document.cookie = name + "="+escape (value) + ";expires=" +exp.toGMTString();
}
//取cookie函数
function getCookie(name){
	var arr = document.cookie.match(new RegExp("(^|)" +name+"=([^;]*)(;|$)"));
	if(arr!=null) return unescape(arr[2]);
	return null;
	
}
//删除cookie
function delCookie(name){
	var exp = new Date();
	exp.setTime(exp.getTime() - 1);
	var cval = getCookie(name);
	if(cval!=null){
		document.cookie= name + "="+cval+";expires="+exp.toGMTString();
	}
	
}